package com.cooper.slidingmenu.utils;

import com.cooper.scrapemedialib.R;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.TextView;

public class FullWatiDialog extends DialogFragment implements
		DialogInterface.OnCancelListener {

	public interface FullWatiDialogListener {

		public abstract void onFullWatingCanceled();
	}

	public static FullWatiDialog newInstance(int msgRes, boolean cancelable) {
		FullWatiDialog fullWatiDialog = new FullWatiDialog();
		Bundle bundle = new Bundle();
		bundle.putInt("WAIT_MSG_RES", msgRes);
		bundle.putBoolean("CAN_CANCALE", cancelable);

		fullWatiDialog.setArguments(bundle);
		return fullWatiDialog;
	}

	public static FullWatiDialog newInstance(String msgText, boolean cancelable) {
		FullWatiDialog fullWatiDialog = new FullWatiDialog();
		Bundle bundle = new Bundle();
		bundle.putString("WAIT_MSG_TEXT", msgText);
		bundle.putBoolean("CAN_CANCALE", cancelable);

		fullWatiDialog.setArguments(bundle);
		return fullWatiDialog;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		Dialog waitDataProgressDialog = new Dialog(getActivity(),
				R.style.Theme_TransparentDialog);
		waitDataProgressDialog
				.setContentView(R.layout.transparent_progress_dialog);
		boolean cancelable = getArguments().getBoolean("CAN_CANCALE", false);
		waitDataProgressDialog.setCancelable(cancelable);
		setCancelable(cancelable);
		if (cancelable) {
			waitDataProgressDialog.setOnCancelListener(this);
		}
		if (getArguments().containsKey("WAIT_MSG_RES")) {
			((TextView) waitDataProgressDialog.findViewById(R.id.progress_text))
					.setText(getArguments().getInt("WAIT_MSG_RES"));
		} else {
			((TextView) waitDataProgressDialog.findViewById(R.id.progress_text))
					.setText(getArguments().getString("WAIT_MSG_TEXT"));
		}
		return waitDataProgressDialog;
	}

	@Override
	public void onCancel(DialogInterface dialog) {
		((FullWatiDialogListener) getActivity()).onFullWatingCanceled();
	}
}
